package ssx.demo.elasticsearchdemo.service;


import org.apache.http.HttpHost;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

@org.springframework.stereotype.Service
public class Service {
    public void fun() throws IOException {
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("node101", 30300, "http")));

        IndexRequest indexRequest = new IndexRequest();
        indexRequest.index("myidx1");
        indexRequest.id("1");

        GetRequest myidx1 = new GetRequest("myidx1");
        myidx1.id("1");
        GetResponse documentFields = restHighLevelClient.get(myidx1, RequestOptions.DEFAULT);
        String s = documentFields.toString();
        System.out.println(s);

//        IndexResponse index = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
//        String s = index.toString();
    }

}
